﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

namespace Sina.Altman.Weibo.Tools
{
    public class ISHelper
    {
        private static Object _thisLock = new Object();

        #region Settings/States helper
        public static T LoadSetting<T>(string keyName, T defaultValue)
        {
            lock (_thisLock)
            {
                try
                {
                    if (IsolatedStorageSettings.ApplicationSettings.Contains(keyName))
                        return (T)IsolatedStorageSettings.ApplicationSettings[keyName];
                    else
                        return defaultValue;
                }
                catch (Exception e)
                {
                    //Logger.LogException(e);
                    return defaultValue;
                }
            }
        }

        public static void SaveSetting(string keyName, object dataToSave)
        {
            lock (_thisLock)
            {
                try
                {
                    IsolatedStorageSettings.ApplicationSettings[keyName] = dataToSave;
                    IsolatedStorageSettings.ApplicationSettings.Save();
                }
                catch (Exception e)
                {
                    //Logger.LogException(e);
                    return;
                }
            }

        }

        public static void RemoveSetting(string keyName)
        {
            lock (_thisLock)
            {
                try
                {
                    IsolatedStorageSettings.ApplicationSettings.Remove(keyName);
                }
                catch (Exception e)
                {
                    //Logger.LogException(e);
                    return;
                }
            }
        }
        #endregion
    }
}
